package configs

import (
	"gatewayConsumer/dto"
	"github.com/pelletier/go-toml/v2"
	log "github.com/sirupsen/logrus"
	"os"
	"sync"
)

type TomlConfigs struct {
	Version string
	Redis   *dto.RedisConfigDto
}

var (
	tconfig *TomlConfigs
	once    sync.Once
)

func GetConfig() *TomlConfigs {
	once.Do(func() {
		log.Infof("info from config")
		log.Warnf("warn from config")
		fileName := "./configs/config.toml"
		content, err := os.ReadFile(fileName)
		if err != nil {
			panic(err)
		}
		tomlText := string(content)

		err2 := toml.Unmarshal([]byte(tomlText), &tconfig) //加载toml文件
		if err2 != nil {
			panic(err2)
		}
	})

	return tconfig
}
